package org.example.repository.dialect.mysql;

import lombok.extern.slf4j.Slf4j;
import org.example.repository.ConditionalOnDriver;
import org.example.repository.RepositoryFactory;
import org.example.repository.SchemaSynchronizer;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.core.JdbcTemplate;

@Configuration
@ConditionalOnDriver(havingValue = "mysql")
@Import(DataSourceAutoConfiguration.class)
@Slf4j
public class MysqlRepositoryConfig {

    @Bean
    public SchemaSynchronizer mysqlSchemaSynchronizer(JdbcTemplate jdbcTemplate) {
        log.info("create mysql schemaSynchronizer");
        return new MysqlSchemaSynchronizer(jdbcTemplate);
    }

    @Bean
    public RepositoryFactory mysqlRepositoryFactory(JdbcTemplate jdbcTemplate) {
        log.info("create mysql repositoryFactory");
        return new MysqlRepositoryFactory(jdbcTemplate);
    }
}
